package org.bluewhale.interact;

import java.io.IOException;
import java.util.EnumSet;
import java.util.List;

import com.xiaonei.api.*;
import com.xiaonei.api.schema.User;
import com.xiaonei.api.schema.UsersGetInfoResponse;

public class GetUserInfo {
	
	private Integer userId;
	private String userName;
	private String birthday;
	private String pic;

	public String getPic() {
		return pic;
	}

	public void getUserInfo(String sessionId, Integer userId) {
		XiaoneiRestClient client = new XiaoneiRestClient(Config.API_KEY,Config.Secret, sessionId);
		
		client.setDebug(true);
		EnumSet<ProfileField> enumFields = EnumSet.of(ProfileField.NAME, ProfileField.BIRTHDAY, ProfileField.TINYURL);

		try {
			client.users_getInfo(userId, enumFields);
		} catch (XiaoneiException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		UsersGetInfoResponse loggedUserGetInfoRes = (UsersGetInfoResponse) client.getResponsePOJO();
		List<User> users = loggedUserGetInfoRes.getUser();
		if (users.size() > 0) {
			this.userId = users.get(0).getUid();
			this.userName = users.get(0).getName();
			this.birthday = users.get(0).getBirthday();
			this.pic = users.get(0).getTinyurl();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		XiaoneiRestClient client = new XiaoneiRestClient(Config.API_KEY,Config.Secret,Config.SessionKey);
		
		client.setDebug(true);
		EnumSet<ProfileField> enumFields = EnumSet.of(ProfileField.NAME, ProfileField.BIRTHDAY);

		client.users_getInfo(79856, enumFields);
		UsersGetInfoResponse loggedUserGetInfoRes = (UsersGetInfoResponse) client.getResponsePOJO();
		List<User> users = loggedUserGetInfoRes.getUser();
		for (User user : users) {
			System.out.println("users.getInfo|Uid|"+user.getUid());
			System.out.println("users.getInfo|Name|"+user.getName());
			System.out.println("users.getInfo|Birthday|"+user.getBirthday());
		}
	}

	public Integer getUserId() {
		return userId;
	}

	public String getUserName() {
		return userName;
	}

	public String getBirthday() {
		return birthday;
	}

}
